#include<bits/stdc++.h>
using namespace std;
int read()
{
	int s=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		s=s*10+ch-'0';
		ch=getchar();
	}
	return f*s;
}
struct edge
{
	int head,next[10010],num;
	int len=0;
}q[1010];
//void dfs(int m)
//{
//	cout<<m<<" ";
//	for(int i=1; i<=q[m].len; ++i) cout<<q[m].next[i]<<" ";
//	cout<<endl;
//	for(int i=1; i<=q[m].len; ++i) dfs(q[m].next[i]);
//}
int n,k,x,y,z,a[100010],b[100010],m,j=1;
int main()
{
	freopen("apple.in","r",stdin);
	freopen("apple.out","w",stdout);
	n=read(),k=read();
	for(int i=1; i<n; ++i)
	{
		x=read(),y=read(),z=read();
		q[x].next[++q[x].len]=y,q[y].head=x,q[y].num=z;
	}
	for(int i=1; i<=k; ++i) cin>>a[100010];
	for(int i=0; i<n; ++i)
		if(q[i].head==0) 
		{
			b[j]=i,m=i;
			break;
		}
//	dfs(m);
	while(q[m].len==0)
		b[++j]=q[m].next[1],m=q[m].next[1];
	cout<<31012<<endl;
	return 0;
}
